home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Include / FWCmd.h < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.9 KB  |  331 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWCmd.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWCMD_H
  11. #define FWCMD_H
  12.  
  13. // ----- Foundation Includes -----
  14.  
  15. #ifndef FWSTDDEF_H
  16. #include "FWStdDef.h"
  17. #endif
  18.  
  19. #ifndef FWEXCLIB_H
  20. #include "FWExcLib.h"
  21. #endif
  22.  
  23. // ----- OpenDoc Includes -----
  24.  
  25. #ifndef FWODTYPS_H
  26. #include "FWODTyps.h"
  27. #endif
  28.  
  29. #ifndef SOM_ODUndo_xh
  30. #include <Undo.xh>
  31. #endif
  32.  
  33. //==============================================================================
  34. //    Forward Declarations
  35. //==============================================================================
  36.  
  37. class FW_CPart;
  38. class FW_CFrame;
  39. class FW_CString;
  40. class FW_CPresentation;
  41. class ODUndo;
  42.  
  43. //==============================================================================
  44. //    Constants
  45. //==============================================================================
  46.  
  47. #define FW_kCanUndo TRUE
  48. #define FW_kCantUndo FALSE
  49.  
  50. //==============================================================================
  51. // class FW_CCommand
  52. //==============================================================================
  53.  
  54. class FW_CCommand
  55. {
  56.   public:
  57.     FW_DECLARE_AUTO(FW_CCommand)
  58.  
  59.   public:
  60.  
  61. //------------------------------------------------------------------------
  62. // --- Initialization/Destruction ---
  63.  
  64.     FW_CCommand(Environment* ev,
  65.                 ODCommandID id,
  66.                 FW_CFrame* frame,
  67.                 FW_Boolean canUndo);
  68.     virtual ~ FW_CCommand();
  69.  
  70. //------------------------------------------------------------------------
  71. // --- Command API ---
  72.  
  73.     FW_Boolean Execute(Environment* ev, FW_Boolean deleteIfNotUndoable = TRUE);
  74.         // Execute the command by calling DoIt, 
  75.         // and take care of OpenDoc Undo/Redo paperwork if necessary.
  76.         // Return TRUE if the command is on the OpenDoc undo stack. The command
  77.         // is automatically deleted if not undoable unless deleteIfNotUndoable is
  78.         // set to false
  79.  
  80.     virtual void DoIt(Environment* ev) = 0;
  81.         // Must be overridden by all commands
  82.  
  83. //------------------------------------------------------------------------
  84. // --- API for Undo-able Commands ---
  85.  
  86.     virtual void UndoIt(Environment* ev);
  87.     virtual void RedoIt(Environment* ev);
  88.         // Undo-able commands must override
  89.         // Default does nothing
  90.  
  91.     virtual void CommitDone(Environment* ev);
  92.         // Called just before the command is deleted.
  93.         // doneState values are kODDone or kODRedone (ODTypes.h)
  94.         // Default calls FreeUndoState
  95.  
  96.     virtual void CommitUndone(Environment* ev);
  97.         // Called just before the command is deleted.
  98.         // doneState value is kODUndone (ODTypes.h)
  99.         // Default calls FreeRedoState
  100.  
  101.     virtual void SaveUndoState(Environment* ev);
  102.     virtual void SaveRedoState(Environment* ev);
  103.         // Save state of data for later undo and redo
  104.         // Default does nothing
  105.  
  106.     virtual void FreeUndoState(Environment* ev);
  107.     virtual void FreeRedoState(Environment* ev);
  108.         // delete data saved for undo and redo
  109.         // Default does nothing
  110.  
  111. //------------------------------------------------------------------------
  112. // --- New API ---
  113. public:
  114.     ODActionType        GetActionType(Environment* ev) const;
  115.  
  116.     FW_Boolean            GetCanUndo(Environment* ev) const;
  117.     void                SetCanUndo(Environment* ev, FW_Boolean canUndo);
  118.     
  119.     FW_Boolean            GetCausesChange(Environment* ev) const;
  120.     void                SetCausesChange(Environment* ev, FW_Boolean causesChange);
  121.     
  122.     ODCommandID            GetCommandID(Environment* ev) const;
  123.     void                SetCommandID(Environment* ev, ODCommandID id);
  124.     
  125.     ODName*                GetUndoString(Environment* ev);
  126.     ODName*                GetRedoString(Environment* ev);
  127.     
  128.     ODUndo*                GetUndo(Environment* ev) const;
  129.  
  130.     FW_CPresentation*    GetPresentation(Environment* ev) const;
  131.     FW_CFrame*            GetSourceFrame(Environment* ev) const;
  132.     FW_CFrame*            GetFrame(Environment* ev) const;
  133.     FW_CPart*            GetPart(Environment* ev) const;
  134.     
  135.     FW_Boolean            HasAddedAction(Environment* ev) const;
  136.  
  137.     void                SetActionType(Environment* ev, ODActionType actionType);
  138.  
  139. protected:
  140.     void                SetMenuStrings(Environment* ev,
  141.                                    const FW_CString& undoString,
  142.                                    const FW_CString& redoString);
  143.     void                SetMenuStrings(Environment* ev,
  144.                                    char* undoChars,
  145.                                    char* redoChars);
  146.     void                SetMenuStringsFromResource(Environment* ev, 
  147.                                                short stringResourceID, 
  148.                                                short undoStringID, 
  149.                                                short redoStringID);
  150.                             // Call one of these to set up menu strings for Undo and Redo
  151.  
  152.     void                AddAction(Environment* ev, 
  153.                               ODActionType actionType, 
  154.                               octet* dataPtr, 
  155.                               unsigned long dataSize,
  156.                               ODName* undoActionLabel,
  157.                               ODName* redoActionLabel);
  158.                             // Call ODUndo::AddActionToHistory; used for transactions
  159.  
  160.     FW_Boolean            IsOKtoEdit(Environment* ev);
  161.                             // Checks whether it's OK to change this part and frame
  162.  
  163. //------------------------------------------------------------------------
  164. //    Implementation Only
  165. //
  166. private:
  167.     void            PrivLoadDefaultUndoStrings(Environment* ev);    
  168.     void            PrivDisposeUndoStrings();
  169.     
  170. //------------------------------------------------------------------------
  171. // --- Data Members ---
  172. private:
  173.     FW_Boolean            fCanUndo;                // Default = TRUE
  174.     FW_Boolean            fCausesChange;            // Default = TRUE
  175.     ODCommandID            fCommandID;
  176.     ODActionType        fActionType;            // Default = kODSingleAction
  177.  
  178.     ODName*                fUndoString;            // string for Undo menu item
  179.     ODName*                fRedoString;            // string for Redo menu item
  180.  
  181.     FW_CPart*            fPart;    
  182.     FW_CFrame*            fFrame;                    // Original Command Frame (might not be valid during Undo/Redo)
  183.     FW_CPresentation*    fPresentation; 
  184.     FW_CFrame*            fSourceFrame;
  185.     
  186.     ODUndo*                fUndo;
  187.     FW_Boolean            fHasAddedAction;        // TRUE if this command has called AddAction
  188.  
  189.     // Don't allow commands to be copied or returned from functions
  190.     FW_CCommand(const FW_CCommand& command);            // Copy constructor
  191.     FW_CCommand& operator=(const FW_CCommand& command);    // Assignment operator
  192. };
  193.  
  194. //========================================================================================
  195. //    FW_CCommand Inlines
  196. //========================================================================================
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CCommand::GetActionType
  200. //----------------------------------------------------------------------------------------
  201. inline ODActionType FW_CCommand::GetActionType(Environment*) const
  202. {
  203.     return fActionType;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_CCommand::GetCanUndo
  208. //----------------------------------------------------------------------------------------
  209. inline FW_Boolean FW_CCommand::GetCanUndo(Environment*) const
  210. {
  211.     return fCanUndo;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CCommand::SetCanUndo
  216. //----------------------------------------------------------------------------------------
  217. inline void FW_CCommand::SetCanUndo(Environment*, FW_Boolean canUndo)
  218. {
  219.     fCanUndo = canUndo;
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CCommand::GetCausesChange
  224. //----------------------------------------------------------------------------------------
  225. inline FW_Boolean FW_CCommand::GetCausesChange(Environment*) const
  226. {
  227.     return fCausesChange;
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    FW_CCommand::SetCausesChange
  232. //----------------------------------------------------------------------------------------
  233. inline void FW_CCommand::SetCausesChange(Environment*, FW_Boolean causesChange)
  234. {
  235.     fCausesChange = causesChange;
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    FW_CCommand::GetCommandID
  240. //----------------------------------------------------------------------------------------
  241. inline ODCommandID FW_CCommand::GetCommandID(Environment*) const
  242. {
  243.     return fCommandID;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CCommand::SetCommandID
  248. //----------------------------------------------------------------------------------------
  249. inline void FW_CCommand::SetCommandID(Environment*, ODCommandID id)
  250. {
  251.     fCommandID = id;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    FW_CCommand::GetUndoString
  256. //----------------------------------------------------------------------------------------
  257. inline ODName* FW_CCommand::GetUndoString(Environment* ev)
  258. {
  259.     if (!fUndoString)
  260.         PrivLoadDefaultUndoStrings(ev);
  261.     return fUndoString;
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    FW_CCommand::GetRedoString
  266. //----------------------------------------------------------------------------------------
  267. inline ODName* FW_CCommand::GetRedoString(Environment* ev)
  268. {
  269.     if (!fRedoString)
  270.         PrivLoadDefaultUndoStrings(ev);
  271.     return fRedoString;
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    FW_CCommand::GetUndo
  276. //----------------------------------------------------------------------------------------
  277. inline ODUndo* FW_CCommand::GetUndo(Environment*) const
  278. {
  279.     return fUndo;
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    FW_CCommand::HasAddedAction
  284. //----------------------------------------------------------------------------------------
  285. inline FW_Boolean FW_CCommand::HasAddedAction(Environment*) const
  286. {
  287.     return fHasAddedAction;
  288. }
  289.  
  290. //----------------------------------------------------------------------------------------
  291. //    FW_CCommand::SetActionType
  292. //----------------------------------------------------------------------------------------
  293. inline void FW_CCommand::SetActionType(Environment*, ODActionType actionType)
  294. {
  295.     fActionType = actionType;
  296. }
  297.  
  298. //----------------------------------------------------------------------------------------
  299. //    FW_CCommand::GetPart
  300. //----------------------------------------------------------------------------------------
  301. inline FW_CPart* FW_CCommand::GetPart(Environment*) const
  302. {
  303.     return fPart;
  304. }
  305.  
  306. //----------------------------------------------------------------------------------------
  307. //    FW_CCommand::GetFrame
  308. //----------------------------------------------------------------------------------------
  309. inline FW_CFrame* FW_CCommand::GetFrame(Environment*) const
  310. {
  311.     return fFrame;
  312. }
  313.  
  314. //----------------------------------------------------------------------------------------
  315. //    FW_CCommand::GetSourceFrame
  316. //----------------------------------------------------------------------------------------
  317. inline FW_CFrame* FW_CCommand::GetSourceFrame(Environment*) const
  318. {
  319.     return fSourceFrame;
  320. }
  321.  
  322. //----------------------------------------------------------------------------------------
  323. //    FW_CCommand::GetPresentation
  324. //----------------------------------------------------------------------------------------
  325. inline FW_CPresentation* FW_CCommand::GetPresentation(Environment*) const
  326. {
  327.     return fPresentation;
  328. }
  329.  
  330. #endif
  331.